package fag.core.game.test.playground.solid;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.util.List;

import fag.core.geometry.Polygon2D;
import fag.core.geometry.Vector2D;

public class Polygon extends AbstractSolid {
	
	private final int x[];
	private final int y[];
	private final int size;
	
	/**
	 * Constructeur paramétré.
	 * @param vertices Liste des sommets du polygone.
	 */
	public Polygon(List<Vector2D> vertices) {
		super(new Polygon2D(vertices));
		
		size = vertices.size();
		x = new int[size];
		y = new int[size];
		
		for(int i = 0; i < vertices.size(); ++i) {
			x[i] = (int)vertices.get(i).getX();
			y[i] = (int)vertices.get(i).getY();
		}
		
		initialize();
	}

	@Override
	protected void draw(Graphics2D graphics2d) {
		
		// Transformation du plan pour peindre l'objet à sa position
		AffineTransform old = graphics2d.getTransform();
		
		synchronized(transformation) {
			graphics2d.transform(transformation);
		}
		
		graphics2d.setColor(color);
		graphics2d.drawPolygon(x, y, size);
		graphics2d.setColor(OUTLINE_COLOR);
		graphics2d.fillPolygon(x, y, size);
		
		// Restauration du contexte graphique
		graphics2d.setTransform(old);
	}
	
	/**
	 * Initialise le solide.
	 */
	private void initialize() {
		setMomentOfInertia(100);
	}
	
}
